package com.nari.ncps.screen.service.impl.coal;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nari.ncps.screen.entity.coal.CoalProdoperStock;
import com.nari.ncps.screen.mapper.coal.CoalProdoperStockMapper;
import com.nari.ncps.screen.service.coal.CoalProdoperStockService;
import com.nari.ncps.screen.vo.coal.CoalInventoryTrendVO;
import com.nari.ncps.screen.vo.coal.CoalInventoryUnitsVO;
import com.nari.ncps.screen.vo.wholeproduct.AnnualStockVO;
import com.nari.ncps.screen.vo.wholeproduct.CoalStockDetailVO;
import com.nari.ncps.screen.vo.wholeproduct.CoalStockYoyVO;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * <p>
 * 生产经营煤炭库存表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class CoalProdoperStockServiceImpl extends ServiceImpl<CoalProdoperStockMapper, CoalProdoperStock> implements CoalProdoperStockService {

    @Override
    public List<CoalInventoryTrendVO> getInventoryTrend(Integer year) {

        // 如果year为null，使用当前年份
        int currentYear = year != null ? year : LocalDate.now().getYear();
        int currentMonth = LocalDate.now().getMonthValue();
        
        // 构建最近6个月的年月列表
        List<CoalInventoryTrendVO> resultList = new ArrayList<>();
        
        // 查询当前年及去年的日数据（date_type=2）
        List<Integer> years = Arrays.asList(currentYear - 1, currentYear);
        LambdaQueryWrapper<CoalProdoperStock> query = new LambdaQueryWrapper<>();
        query.in(CoalProdoperStock::getYear, years)
             .eq(CoalProdoperStock::getDateType, 2);  // 2表示日数据
        
        List<CoalProdoperStock> dataList = this.list(query);
        
        // 处理数据为空的情况
        if (dataList == null || dataList.isEmpty()) {
            // 返回空列表，但仍然包含年月信息
            for (int i = 5; i >= 0; i--) {
                LocalDate monthDate = LocalDate.of(currentYear, currentMonth, 1).minusMonths(i);
                CoalInventoryTrendVO vo = new CoalInventoryTrendVO();
                vo.setYear(monthDate.getYear());
                vo.setMonth(monthDate.getMonthValue());
                vo.setCurrentStock(BigDecimal.ZERO);
                vo.setLastYearStock(BigDecimal.ZERO);
                resultList.add(vo);
            }
            return resultList;
        }
        
        // 按年月分组汇总数据
        java.util.Map<String, BigDecimal> stockMap = new java.util.HashMap<>();
        for (CoalProdoperStock data : dataList) {
            if (data.getYear() != null && data.getMonth() != null && data.getCurrentStock() != null) {
                String key = data.getYear() + "-" + data.getMonth();
                BigDecimal sum = stockMap.getOrDefault(key, BigDecimal.ZERO);
                stockMap.put(key, sum.add(data.getCurrentStock()));
            }
        }
        
        // 构建最近6个月的结果
        for (int i = 5; i >= 0; i--) {
            LocalDate monthDate = LocalDate.of(currentYear, currentMonth, 1).minusMonths(i);
            int queryYear = monthDate.getYear();
            int queryMonth = monthDate.getMonthValue();
            
            CoalInventoryTrendVO vo = new CoalInventoryTrendVO();
            vo.setYear(queryYear);
            vo.setMonth(queryMonth);
            
            // 获取当前年月的库存汇总
            String currentKey = queryYear + "-" + queryMonth;
            BigDecimal currentStock = stockMap.get(currentKey);
            if (currentStock != null) {
                vo.setCurrentStock(currentStock);
            } else {
                vo.setCurrentStock(BigDecimal.ZERO);
            }
            
            // 获取去年同期的库存汇总
            String lastYearKey = (queryYear - 1) + "-" + queryMonth;
            BigDecimal lastYearStock = stockMap.get(lastYearKey);
            if (lastYearStock != null) {
                vo.setLastYearStock(lastYearStock);
            } else {
                vo.setLastYearStock(BigDecimal.ZERO);
            }
            
            resultList.add(vo);
        }
        
        return resultList;
    }

    @Override
    public List<CoalInventoryUnitsVO> getInventoryByUnits(Integer year) {
        // 如果year为null，使用当前年份

        LocalDate today = LocalDate.now();
        // 获取前一天
        LocalDate yesterday = today.minusDays(1);
        int currentYear = yesterday.getYear();
        int currentMonth = yesterday.getMonthValue();
        int currentDay = yesterday.getDayOfMonth();
        
        // 查询指定年份的所有库存数据
        LambdaQueryWrapper<CoalProdoperStock> query = new LambdaQueryWrapper<>();
        query.eq(CoalProdoperStock::getYear, currentYear).eq(CoalProdoperStock::getMonth, currentMonth).eq(CoalProdoperStock::getDay, currentDay).eq(CoalProdoperStock::getDateType, 2);
        
        List<CoalProdoperStock> dataList = this.list(query);
        
        // 处理数据为空的情况
        List<CoalInventoryUnitsVO> resultList = new ArrayList<>();
        if (dataList == null || dataList.isEmpty()) {
            ArrayList<CoalInventoryUnitsVO> coalInventoryUnitsVOS = new ArrayList<>();
            //return resultList;
            CoalInventoryUnitsVO coalInventoryUnitsVO1 = new CoalInventoryUnitsVO();
            coalInventoryUnitsVO1.setUnitCode("50000004");
            coalInventoryUnitsVO1.setUnitName("内蒙古南露天煤矿");
            coalInventoryUnitsVO1.setCurrentStock(BigDecimal.ZERO);
            coalInventoryUnitsVOS.add(coalInventoryUnitsVO1);

            CoalInventoryUnitsVO coalInventoryUnitsVO2 = new CoalInventoryUnitsVO();
            coalInventoryUnitsVO2.setUnitCode("50000005");
            coalInventoryUnitsVO2.setUnitName("内蒙古白音华三号矿");
            coalInventoryUnitsVO2.setCurrentStock(BigDecimal.ZERO);
            coalInventoryUnitsVOS.add(coalInventoryUnitsVO2);

            CoalInventoryUnitsVO coalInventoryUnitsVO3 = new CoalInventoryUnitsVO();
            coalInventoryUnitsVO3.setUnitCode("50000007");
            coalInventoryUnitsVO3.setUnitName("内蒙古北露天煤矿");
            coalInventoryUnitsVO3.setCurrentStock(BigDecimal.ZERO);
            coalInventoryUnitsVOS.add(coalInventoryUnitsVO3);

            CoalInventoryUnitsVO coalInventoryUnitsVO4 = new CoalInventoryUnitsVO();
            coalInventoryUnitsVO4.setUnitCode("50000008");
            coalInventoryUnitsVO4.setUnitName("内蒙古白音华二号矿");
            coalInventoryUnitsVO4.setCurrentStock(BigDecimal.ZERO);
            coalInventoryUnitsVOS.add(coalInventoryUnitsVO4);

            CoalInventoryUnitsVO coalInventoryUnitsVO5 = new CoalInventoryUnitsVO();
            coalInventoryUnitsVO5.setUnitCode("50000006");
            coalInventoryUnitsVO5.setUnitName("内蒙古扎鲁特旗扎哈淖尔煤业");
            coalInventoryUnitsVO5.setCurrentStock(BigDecimal.ZERO);
            coalInventoryUnitsVOS.add(coalInventoryUnitsVO5);


            return coalInventoryUnitsVOS;
        }
        
        // 按org_code分组汇总current_stock
        java.util.Map<String, CoalInventoryUnitsVO> unitMap = new java.util.LinkedHashMap<>();
        
        for (CoalProdoperStock data : dataList) {
            if (data.getOrgCode() == null) {
                continue;
            }
            
            String orgCode = data.getOrgCode();
            
            // 获取或创建该单位的VO对象
            CoalInventoryUnitsVO vo = unitMap.get(orgCode);
            if (vo == null) {
                vo = new CoalInventoryUnitsVO();
                vo.setUnitCode(orgCode);
                vo.setUnitName(data.getOrgName());
                vo.setCurrentStock(BigDecimal.ZERO);
                unitMap.put(orgCode, vo);
            }
            
            // 汇总current_stock
            if (data.getCurrentStock() != null) {
                vo.setCurrentStock(vo.getCurrentStock().add(data.getCurrentStock()));
            }
        }
        
        // 转换为列表
        resultList.addAll(unitMap.values());
        
        // 按org_code排序
        resultList.sort(Comparator.comparing(CoalInventoryUnitsVO::getUnitCode));
        
        return resultList;
    }

    @Override
    public List<AnnualStockVO> getAnnualStock(Integer year) {
        List<AnnualStockVO> resultList = new ArrayList<>();
        BigDecimal divisor = new BigDecimal("10000");  // 将吨转换为万吨



//        应急更改
        LambdaQueryWrapper<CoalProdoperStock> query = new LambdaQueryWrapper<>();
        query.eq(CoalProdoperStock::getDateType, 0)
                .eq(CoalProdoperStock::getOrgCode, "100360");

        List<CoalProdoperStock> dataList = this.list(query);
        for(CoalProdoperStock data:dataList){
            AnnualStockVO vo=new AnnualStockVO();
            vo.setYear(data.getYear());
            vo.setCurrentStock(data.getCurrentStock());
            resultList.add(vo);
        }
//        // 获取当前年份和月份
//        int currentYear = LocalDate.now().getYear();
//        int currentMonth = LocalDate.now().getMonthValue();
//
//        // 查询最近5年的数据
//        for (int i = 4; i >= 0; i--) {
//            int targetYear = currentYear - i;
//
//            // 先尝试查询目标年份当前月份的数据
//            LambdaQueryWrapper<CoalProdoperStock> query = new LambdaQueryWrapper<>();
//            query.eq(CoalProdoperStock::getYear, targetYear)
//                 .eq(CoalProdoperStock::getMonth, currentMonth)
//                 .eq(CoalProdoperStock::getOrgCode, "100360");
//
////            CoalProdoperStock data = this.getOne(query);
//            CoalProdoperStock data = this.list(query).stream().findFirst().orElse(null);
//
//            // 如果当前月份没有数据，查询该年最新月份的数据
//            if (data == null) {
//                LambdaQueryWrapper<CoalProdoperStock> latestQuery = new LambdaQueryWrapper<>();
//                latestQuery.eq(CoalProdoperStock::getYear, targetYear)
//                          .eq(CoalProdoperStock::getOrgCode, "100360")
//                          .orderByDesc(CoalProdoperStock::getMonth)
//                          .last("LIMIT 1");
//
////                data = this.getOne(latestQuery);
//                data = this.list(latestQuery).stream().findFirst().orElse(null);
//
//            }
//
//            // 如果该年有数据，添加到结果列表
//            if (data != null && data.getCurrentStock() != null) {
//                AnnualStockVO vo = new AnnualStockVO();
//                vo.setYear(targetYear);
//                vo.setCurrentStock(data.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
//                resultList.add(vo);
//            }
//        }
        
        return resultList;
    }

    @Override
    public List<AnnualStockVO> getAnnualStockNow(Integer year) {
        List<AnnualStockVO> resultList = new ArrayList<>();
        BigDecimal divisor = new BigDecimal("10000");  // 将吨转换为万吨
//        应急更改  // 获取最新的数据
        LambdaQueryWrapper<CoalProdoperStock> query = new LambdaQueryWrapper<>();
        query.eq(CoalProdoperStock::getDateType, 2)
                .eq(CoalProdoperStock::getOrgCode, "100360").orderByDesc(CoalProdoperStock::getStatisticTime).last("LIMIT 1");;
        List<CoalProdoperStock> dataList = this.list(query);
        for(CoalProdoperStock data:dataList){
            AnnualStockVO vo=new AnnualStockVO();
            vo.setYear(data.getYear());
            vo.setCurrentStock(data.getCurrentStock());
            resultList.add(vo);
        }

        return resultList;
    }


    @Override
    public CoalStockDetailVO getCoalStockDetail(Integer year) {

        // 获取当前日期
        LocalDate today = LocalDate.now();
        // 获取30天前的日期
        LocalDate thirtyDaysAgo = today.minusDays(30);

        CoalStockDetailVO vo = new CoalStockDetailVO();
        BigDecimal divisor = new BigDecimal("10000");  // 将吨转换为万吨

        // 获取当前年份和月份
        int currentYear = year != null ? year : today.getYear();
        int currentMonth = today.getMonthValue();
        int currentDay = today.getDayOfMonth();

        // 查询本月库存数据
        LambdaQueryWrapper<CoalProdoperStock> currentQuery = new LambdaQueryWrapper<>();
        currentQuery.eq(CoalProdoperStock::getYear, currentYear)
                    .eq(CoalProdoperStock::getMonth, currentMonth)
                    .eq(CoalProdoperStock::getDay, currentDay);
//                   .eq(CoalProdoperStock::getOrgCode, "TOTAL");
//        CoalProdoperStock currentData = this.getOne(currentQuery);
        CoalProdoperStock currentData = this.list(currentQuery).stream().findFirst().orElse(null);

        // 查询上月库存数据
        int lastMonth = thirtyDaysAgo.getMonthValue();
        int lastMonthYear = thirtyDaysAgo.getYear();
        int lastMonthDay = thirtyDaysAgo.getDayOfMonth();


        LambdaQueryWrapper<CoalProdoperStock> lastMonthQuery = new LambdaQueryWrapper<>();
        lastMonthQuery.eq(CoalProdoperStock::getYear, lastMonthYear)
                     .eq(CoalProdoperStock::getMonth, lastMonth)
                     .eq(CoalProdoperStock::getDay, lastMonthDay);
//                     .eq(CoalProdoperStock::getOrgCode, "TOTAL");
//        CoalProdoperStock lastMonthData = this.getOne(lastMonthQuery);
        CoalProdoperStock lastMonthData = this.list(lastMonthQuery).stream().findFirst().orElse(null);

        // 设置本月库存量
        if (currentData != null && currentData.getCurrentStock() != null) {
//            vo.setCurrentMonthStock(currentData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
            vo.setCurrentMonthStock(currentData.getCurrentStock());

        }

        // 设置上月库存量
        if (lastMonthData != null && lastMonthData.getCurrentStock() != null) {
            vo.setLastMonthStock(lastMonthData.getCurrentStock());
//            vo.setLastMonthStock(lastMonthData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
        }

        // 计算库存量环比(%) = (本月库存 - 上月库存) / 上月库存 * 100
        if (vo.getCurrentMonthStock() != null && vo.getLastMonthStock() != null
            && vo.getLastMonthStock().compareTo(BigDecimal.ZERO) != 0) {
            BigDecimal stockMomRate = vo.getCurrentMonthStock().subtract(vo.getLastMonthStock())
                    .divide(vo.getLastMonthStock(), 4, RoundingMode.HALF_UP)
                    .multiply(new BigDecimal("100"))
                    .setScale(2, RoundingMode.HALF_UP);
            vo.setStockMomRate(stockMomRate);
        }

        // 设置热量占比（暂时使用固定值，实际应从配置或其他表获取）
        vo.setLowHeatRatio(new BigDecimal("40"));
        vo.setNormalHeatRatio(new BigDecimal("20"));
        vo.setMediumHeatRatio(new BigDecimal("30"));
        vo.setHighHeatRatio(new BigDecimal("10"));






        return vo;


//        CoalStockDetailVO vo = new CoalStockDetailVO();
//        BigDecimal divisor = new BigDecimal("10000");  // 将吨转换为万吨
//
//        // 获取当前年份和月份
//        int currentYear = year != null ? year : LocalDate.now().getYear();
//        int currentMonth = LocalDate.now().getMonthValue()-1;
//
//        // 查询本月库存数据
//        LambdaQueryWrapper<CoalProdoperStock> currentQuery = new LambdaQueryWrapper<>();
//        currentQuery.eq(CoalProdoperStock::getYear, currentYear)
//                   .eq(CoalProdoperStock::getMonth, currentMonth);
////                   .eq(CoalProdoperStock::getOrgCode, "TOTAL");
////        CoalProdoperStock currentData = this.getOne(currentQuery);
//        CoalProdoperStock currentData = this.list(currentQuery).stream().findFirst().orElse(null);
//
//        // 查询上月库存数据
//        int lastMonth = currentMonth - 1;
//        int lastMonthYear = currentYear;
//        if (lastMonth == 0) {
//            lastMonth = 12;
//            lastMonthYear = currentYear - 1;
//        }
//
//        LambdaQueryWrapper<CoalProdoperStock> lastMonthQuery = new LambdaQueryWrapper<>();
//        lastMonthQuery.eq(CoalProdoperStock::getYear, lastMonthYear)
//                     .eq(CoalProdoperStock::getMonth, lastMonth);
////                     .eq(CoalProdoperStock::getOrgCode, "TOTAL");
////        CoalProdoperStock lastMonthData = this.getOne(lastMonthQuery);
//        CoalProdoperStock lastMonthData = this.list(lastMonthQuery).stream().findFirst().orElse(null);
//
//        // 设置本月库存量
//        if (currentData != null && currentData.getCurrentStock() != null) {
////            vo.setCurrentMonthStock(currentData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
//            vo.setCurrentMonthStock(currentData.getCurrentStock());
//
//        }
//
//        // 设置上月库存量
//        if (lastMonthData != null && lastMonthData.getCurrentStock() != null) {
//            vo.setLastMonthStock(lastMonthData.getCurrentStock());
////            vo.setLastMonthStock(lastMonthData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
//        }
//
//        // 计算库存量环比(%) = (本月库存 - 上月库存) / 上月库存 * 100
//        if (vo.getCurrentMonthStock() != null && vo.getLastMonthStock() != null
//            && vo.getLastMonthStock().compareTo(BigDecimal.ZERO) != 0) {
//            BigDecimal stockMomRate = vo.getCurrentMonthStock().subtract(vo.getLastMonthStock())
//                    .divide(vo.getLastMonthStock(), 4, RoundingMode.HALF_UP)
//                    .multiply(new BigDecimal("100"))
//                    .setScale(2, RoundingMode.HALF_UP);
//            vo.setStockMomRate(stockMomRate);
//        }
//
//        // 设置热量占比（暂时使用固定值，实际应从配置或其他表获取）
//        vo.setLowHeatRatio(new BigDecimal("40"));
//        vo.setNormalHeatRatio(new BigDecimal("20"));
//        vo.setMediumHeatRatio(new BigDecimal("30"));
//        vo.setHighHeatRatio(new BigDecimal("10"));
//        return vo;
    }

    @Override
    public CoalStockYoyVO getCoalStockYoy(Integer year) {

        LocalDate currentDate = LocalDate.now();

        LocalDate lastYearSameDate = currentDate.minusYears(1);

        CoalStockYoyVO vo = new CoalStockYoyVO();
        BigDecimal divisor = new BigDecimal("10000");  // 将吨转换为万吨


        LocalDate today = LocalDate.now();
        // 获取前一天
        LocalDate yesterday = today.minusDays(1);
        int currentYear = yesterday.getYear();
        int currentMonth = yesterday.getMonthValue();
        int currentDay = yesterday.getDayOfMonth();



        // 查询本月日库存数据（当前年、当前月、当前日）
        LambdaQueryWrapper<CoalProdoperStock> currentQuery = new LambdaQueryWrapper<>();
        currentQuery.eq(CoalProdoperStock::getYear, currentYear)
                .eq(CoalProdoperStock::getMonth, currentMonth)
                .eq(CoalProdoperStock::getDay, currentDay);
//                .eq(CoalProdoperStock::getOrgCode, "TOTAL");
//        CoalProdoperStock currentData = this.getOne(currentQuery);
        CoalProdoperStock currentData = this.list(currentQuery).stream().findFirst().orElse(null);

        // 查询去年同期库存数据（去年、当前月、当前日）
        int lastYear = lastYearSameDate.getYear();
        int lastMonth = lastYearSameDate.getYear();
        int lastDay = lastYearSameDate.getYear();

        LambdaQueryWrapper<CoalProdoperStock> lastYearQuery = new LambdaQueryWrapper<>();
        lastYearQuery.eq(CoalProdoperStock::getYear, lastYear)
                .eq(CoalProdoperStock::getMonth, lastMonth)
                .eq(CoalProdoperStock::getDay, lastDay);
//                .eq(CoalProdoperStock::getOrgCode, "TOTAL");
//        CoalProdoperStock lastYearData = this.getOne(lastYearQuery);
        CoalProdoperStock lastYearData = this.list(lastYearQuery).stream().findFirst().orElse(null);

        // 设置本月库存量
        if (currentData != null && currentData.getCurrentStock() != null) {
//            vo.setCurrentMonthStock(currentData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
            vo.setCurrentMonthStock(currentData.getCurrentStock());
        }

        // 设置去年同期库存量
        if (lastYearData != null && lastYearData.getCurrentStock() != null) {
            vo.setLastYearSamePeriodStock(lastYearData.getCurrentStock());
//            vo.setLastYearSamePeriodStock(lastYearData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
        }

        // 计算库存量同比(%) = (本月库存 - 去年同期库存) / 去年同期库存 * 100
        if (vo.getCurrentMonthStock() != null && vo.getLastYearSamePeriodStock() != null
                && vo.getLastYearSamePeriodStock().compareTo(BigDecimal.ZERO) != 0) {
            BigDecimal stockYoyRate = vo.getCurrentMonthStock().subtract(vo.getLastYearSamePeriodStock())
                    .divide(vo.getLastYearSamePeriodStock(), 4, RoundingMode.HALF_UP)
                    .multiply(new BigDecimal("100"))
                    .setScale(2, RoundingMode.HALF_UP);
            vo.setStockYoyRate(stockYoyRate);
        }

        // 设置热量占比（暂时使用固定值，实际应从配置或其他表获取）
        vo.setLowHeatRatio(new BigDecimal("35"));
        vo.setNormalHeatRatio(new BigDecimal("15"));
        vo.setMediumHeatRatio(new BigDecimal("35"));
        vo.setHighHeatRatio(new BigDecimal("15"));

        return vo;

//        CoalStockYoyVO vo = new CoalStockYoyVO();
//        BigDecimal divisor = new BigDecimal("10000");  // 将吨转换为万吨
//
//        // 获取当前年份和月份
//        int currentYear = year != null ? year : LocalDate.now().getYear();
//        int currentMonth = LocalDate.now().getMonthValue()-1;
//
//        // 查询本月库存数据（当前年、当前月）
//        LambdaQueryWrapper<CoalProdoperStock> currentQuery = new LambdaQueryWrapper<>();
//        currentQuery.eq(CoalProdoperStock::getYear, currentYear)
//                .eq(CoalProdoperStock::getMonth, currentMonth);
////                .eq(CoalProdoperStock::getOrgCode, "TOTAL");
////        CoalProdoperStock currentData = this.getOne(currentQuery);
//        CoalProdoperStock currentData = this.list(currentQuery).stream().findFirst().orElse(null);
//
//        // 查询去年同期库存数据（去年、当前月）
//        int lastYear = currentYear - 1;
//        LambdaQueryWrapper<CoalProdoperStock> lastYearQuery = new LambdaQueryWrapper<>();
//        lastYearQuery.eq(CoalProdoperStock::getYear, lastYear)
//                .eq(CoalProdoperStock::getMonth, currentMonth);
////                .eq(CoalProdoperStock::getOrgCode, "TOTAL");
////        CoalProdoperStock lastYearData = this.getOne(lastYearQuery);
//        CoalProdoperStock lastYearData = this.list(lastYearQuery).stream().findFirst().orElse(null);
//
//        // 设置本月库存量
//        if (currentData != null && currentData.getCurrentStock() != null) {
////            vo.setCurrentMonthStock(currentData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
//            vo.setCurrentMonthStock(currentData.getCurrentStock());
//        }
//
//        // 设置去年同期库存量
//        if (lastYearData != null && lastYearData.getCurrentStock() != null) {
//            vo.setLastYearSamePeriodStock(lastYearData.getCurrentStock());
////            vo.setLastYearSamePeriodStock(lastYearData.getCurrentStock().divide(divisor, 2, RoundingMode.HALF_UP));
//        }
//
//        // 计算库存量同比(%) = (本月库存 - 去年同期库存) / 去年同期库存 * 100
//        if (vo.getCurrentMonthStock() != null && vo.getLastYearSamePeriodStock() != null
//                && vo.getLastYearSamePeriodStock().compareTo(BigDecimal.ZERO) != 0) {
//            BigDecimal stockYoyRate = vo.getCurrentMonthStock().subtract(vo.getLastYearSamePeriodStock())
//                    .divide(vo.getLastYearSamePeriodStock(), 4, RoundingMode.HALF_UP)
//                    .multiply(new BigDecimal("100"))
//                    .setScale(2, RoundingMode.HALF_UP);
//            vo.setStockYoyRate(stockYoyRate);
//        }
//
//        // 设置热量占比（暂时使用固定值，实际应从配置或其他表获取）
//        vo.setLowHeatRatio(new BigDecimal("35"));
//        vo.setNormalHeatRatio(new BigDecimal("15"));
//        vo.setMediumHeatRatio(new BigDecimal("35"));
//        vo.setHighHeatRatio(new BigDecimal("15"));
//
//        return vo;
//

    }

}
